import {Sequelize} from "sequelize";
import config from "./config/config.js"

/**
 * 创建数据库实例
 * @type {Sequelize}
 */
const sequelize = new Sequelize({
    database: config.dbConfig.database,
    username: config.dbConfig.username,
    password: config.dbConfig.password,
    host: config.dbConfig.host,
    port: config.dbConfig.port,
    dialect: "mysql",
    logging: console.log,
});

// 测试连接
sequelize
    .authenticate()
    .then(() => {
        console.log("MySQL client connected");
    })
    .catch((e) => {
        console.error("Unable to connect to MySQL", e);
    });

export default sequelize;
